package com.bbx.taxi.client.Util;

import com.bbx.api.util.LogUtils;

import android.content.Context;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;

/** 
 * @Path com.bbx.taxi.client.Util.WakeLock.java
 * @Author 严旭文
 * @Date 2016-1-14 下午5:36:48
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class WakeLockUtil {
	private static WakeLock wakeLock = null;

	/**
	 * 获取电源锁，保持该服务在屏幕熄灭时仍然获取CPU时，保持运行
	 */
	public static void acquireWakeLock(Context context) {
		LogUtils.e("bbx","唤醒");
		PowerManager powerManager = (PowerManager)(context.getSystemService(Context.POWER_SERVICE));   
		wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");   
		wakeLock.acquire(); 
	}

	// 释放设备电源锁
	public static void releaseWakeLock() {
		LogUtils.e("bbx","释放");
		if (null != wakeLock && wakeLock.isHeld()) {
			LogUtils.e("bbx","释放电源锁");
			wakeLock.release();
			wakeLock = null;
		}
	}
	public static void setWifiNeverSleep(Context context){
		  int wifiSleepPolicy=0;
		  wifiSleepPolicy=Settings.System.getInt(context.getContentResolver(),
		                    android.provider.Settings.System.WIFI_SLEEP_POLICY,
		                    Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
		  LogUtils.e("bbx","---> 修改前的Wifi休眠策略值 WIFI_SLEEP_POLICY="+wifiSleepPolicy);
		   
		   
		  Settings.System.putInt(context.getContentResolver(),
		            android.provider.Settings.System.WIFI_SLEEP_POLICY,
		            Settings.System.WIFI_SLEEP_POLICY_NEVER);
		   
		   
		  wifiSleepPolicy=Settings.System.getInt(context.getContentResolver(),
		        android.provider.Settings.System.WIFI_SLEEP_POLICY,
		        Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
		  LogUtils.e("bbx","---> 修改后的Wifi休眠策略值 WIFI_SLEEP_POLICY="+wifiSleepPolicy);
		 }
}
